﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace GameStudio.Common
{
    public class FileListner
    {
        FileSystemWatcher watcher = new FileSystemWatcher();

        public FileListner()
        {

        }
        public void Execute()
        {
            Program.EventAggregator.GetEvent<FileOpenEvent>().Subscribe(OnFileOpend);

        }

        public void OnFileOpend(string filepath)
        {
            watcher.Path = Path.GetDirectoryName(filepath);
            watcher.Filter = Path.GetFileName(filepath);
            watcher.EnableRaisingEvents = true;
            watcher.Changed +=new FileSystemEventHandler(watcher_Changed);
        }

        void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            Program.EventAggregator.GetEvent<FileOpenEvent>().Publish(e.FullPath);
        }
    }
}
